function hello(txt: string): void {
  console.log(`Hello ${txt}`)
}

const hello01 = function (txt: string): void {
  console.log(`Hello ${txt}`)
}

const hello02: (txt: string) => void = function (txt: string): void {
  console.log(`Hello ${txt}`)
}

type MyFunc = (string, number) => number // (string: any, number: any) => number

let f1: (num: string) => number

f1 = function (num: string) {
  return Number(num)
}

type MyFunc2 = (txt: string) => void

let f2: MyFunc2 = function (txt: string): void {
  console.log(`Hello ${txt}`)
}

let myFunc3: (a: number, b: number) => number

// 函数的实际参数个数，可以少于类型指定的参数个数，但是不能多于，即 TypeScript 允许省略参数。
myFunc3 = (a: number) => a
// myFunc3 = (a: number, b: number, c: number) => a + b + c 报错

let x = (a: number) => a
let y = (a: number, b: number) => a + b

y = x
// x = y 报错

function add(x: number, y: number): number {
  return x + y
}

const myAdd: typeof add = function (a, b) {
  return a + b
}

// 函数类型还可以采用对象的写法 比较奇怪~
let add1: {
  (x: number, y: number): number
}

add1 = function (x, y) {
  return x + y
}

function f(x: number) {
  console.log(x)
}

f.version = '1.0'

let foo: {
  (x: number): void
  version: string
} = f

// 函数类型也可以使用 Interface 来声明，这种写法就是对象写法的翻版
interface MyAdd {
  (x: number, y: number): number
}

let add2: MyAdd = function (x, y) {
  return x + y
}
